package com.contexttree.filereader;

import java.io.IOException;


/**
 * This class manage the execution of external script
 * Politecnico di Milano
 * @author Paolo Barbaglia
 * @author Filippo Ferrari
 *
 */

public class ExeScript {

	public static void execute(String scriptname, String filename, String minsup, String minconf, String maxErrors) throws InterruptedException{
		//lancia il file eseguibile esterno
		String command[] = {scriptname, filename, minsup, minconf, maxErrors};
        
        try {
                Process pr = Runtime.getRuntime().exec(command);
                pr.waitFor();
                
        } catch (IOException e) {
                e.printStackTrace();
                e.notifyAll();
        }  	
	}

	public static void deleteFiles(String filename, String minsup, String minconf, String maxErrors, String path){
		//elimina i files doppi e quelli inutilizzati
		
		String command = "cp ./visteTesto_minsup" + minsup + "_minconf" + minconf + "_maxerrors" + maxErrors + "_" + filename + ".txt " + path;
		
		try {
			Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        	e.printStackTrace();
        	e.notifyAll();
        }
		
		command = "cp ./outputDBCoverage_minsup" + minsup + "_minconf" + minconf + "_maxerrors" + maxErrors + "_" + filename + ".txt " + path;
		
		try {
			Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        	e.printStackTrace();
        	e.notifyAll();
        }
		
		command = "rm -f ./outputDBCoverage_minsup" + minsup + "_minconf" + minconf + "_maxerrors" + maxErrors + "_" + filename + ".txt";
		
		try {
			Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        	e.printStackTrace();
        	e.notifyAll();
        }
		
		command = "rm -f " + "./" + filename + "All.dat";
        
		try {
			Runtime.getRuntime().exec(command);
		} catch (IOException e) {
			e.printStackTrace();
			e.notifyAll();
		}
	
		command = "rm -f " + "./" + filename + "All.diz";
    
		try {
			Runtime.getRuntime().exec(command);
		} catch (IOException e) {
			e.printStackTrace();
			e.notifyAll();
		}
		
		command = "rm -f ./visteTesto_minsup" + minsup + "_minconf" + minconf + "_maxerrors" + maxErrors + "_" + filename + ".txt";
		
		try {
			Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        	e.printStackTrace();
        	e.notifyAll();
        }
		
	}
         
}